package router

import (
	"net/http"
	"project/pkg/logger"
	"project/pkg/mildware"

	"github.com/gin-gonic/gin"
)

var routers []router

func AddRouter(r ...router) {
	routers = append(routers, r...)
}

type router interface {
	Router(*gin.Engine)
}
type Router struct {
	E *gin.Engine
}

func (r *Router) Router(val router) {
	val.Router(r.E)
}
func NewHttp(v *gin.Engine) *Router {
	return &Router{E: v}
}

func Init(e *gin.Engine) *gin.Engine {
	rr := NewHttp(e)
	rr.E.Use(logger.GinLogger(), logger.GinRecovery(true), mildware.CORSMiddleware())
	rr.E.GET("ping", func(context *gin.Context) {
		context.JSON(http.StatusOK, gin.H{"success": 1000})
	})
	for _, router := range routers {
		rr.Router(router)
	}
	return rr.E
}
